package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/application")
@Slf4j
public class ApplicationController {
    @Autowired
    ApplicationService applicationService;

    @PostMapping("save")
    public JsonResult saveApplication(ApplicationSaveParam applicationSaveParam){
        log.debug("保存申请单,{}",applicationSaveParam);
        applicationService.saveApplication(applicationSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("select")
    public JsonResult selectApplication(ApplicationQuery applicationQuery){
        log.debug("查询申请单,{}",applicationQuery);
        List<ApplicationVO> list =applicationService.selectApplication(applicationQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("cancel/{id}")
    public JsonResult cancel(@PathVariable Long id){
        log.debug("撤销申请单,{}",id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }

    @PostMapping("distribute/{id}/{vehicleId}")
    public JsonResult distribute(@PathVariable Long id,@PathVariable Long vehicleId){
        log.debug("分配车辆,{},{}",id,vehicleId);
        applicationService.distribute(id,vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("back/{id}/{vehicleId}")
    public JsonResult back(@PathVariable Long id,@PathVariable Long vehicleId){
        log.debug("还车,{},{}",id,vehicleId);
        applicationService.back(id,vehicleId);
        return JsonResult.ok();
    }

}
